package cn.com.nxt.txb;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.x;

import cn.com.nxt.txb.httpdelegate.LinkDelegate;
import cn.com.nxt.txb.util.AppUtil;

@ContentView(R.layout.activity_invite_download)
public class InviteDownloadActivity extends BaseActivity {
    private LinkDelegate linkDelegate;
    private byte linkFlag = (byte) 0x87;
    private String download;
    private String function;
    private String usedesc;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);//注解绑定
        linkDelegate=new LinkDelegate(this);
        linkDelegate.linkerAddrs(linkFlag);
    }

    @Event({R.id.ll_download})
    private void onViewClick(View v) {
        switch (v.getId()) {
            case R.id.ll_download:
                if(AppUtil.isBlank(download))
                    return;
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse(download);
                intent.setData(content_url);
                startActivity(intent);
                break;
        }
    }
    @Override
    public void success(String result, byte flag) {
        super.success(result, flag);
        try {
            JSONObject obj=new JSONObject(result);
            download=obj.optString("download");
            function=obj.optString("function");
            usedesc=obj.optString("usedesc");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
